package cn.qianyan.Filter;

import cn.qianyan.beans.UserRight;
import cn.qianyan.beans.User;
import cn.qianyan.dao.MenuManaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author:
 * @createDate:
 * @description:
 */
public class UserRightFilter implements HandlerInterceptor {

    @Autowired
    private MenuManaDao menuManaDao;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        UserRight userRight = menuManaDao.selectSingle(user.getUright());

        //请求路径
        String servletPath = request.getServletPath();

        if(userRight.getArea()==1){
            return true;
        }
        return false;
    }
}
